<template>
  <div>
    <van-row>
      <van-col span="8">
        组织名称：
        <el-input v-model="text" placeholder="请输入内容"></el-input>
      </van-col>
      <van-col span="8">
        <van-button>查询</van-button>
        <van-button @click="shuaxin">重置</van-button>
        <van-button @click="ces">新增</van-button>
        <van-popup v-model:show="shows" align="left">
          组织名称:
          <el-input v-model="form.name" placeholder="请输入内容"></el-input>
          组织类型:
          <el-radio v-model="form.radio" label="1">公司</el-radio>
          <el-radio v-model="form.radio" label="2">部门</el-radio>
          <br>
          <van-button type="primary" @click="add_tissue">提交</van-button>
          <van-button type="primary" @click="quxiao">取消</van-button>
        </van-popup>
      </van-col>
      <van-col span="8">
        <div>
          <van-uploader :after-read="uploader">
            <van-uploader>
              <van-button icon="plus" type="primary">导入</van-button>
            </van-uploader>
          </van-uploader>
        </div>
      </van-col>
    </van-row>
    <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"/>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: "class_s",
  data() {
    return {
      text: '',
      filterText: '',
      data: [],
      shows: false,
      form: {radio: '', pid: 0},
      defaultProps: {
        children: 'children',
        label: 'label',


      },
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    },
  },
  methods: {
    handleNodeClick(data) {
      this.form.pid = data.id
    },
    //展开
    ces() {
      this.shows = true
    },
    //收起
    quxiao() {
      this.shows = false
    },
    tissue_list() {
      axios({url: 'tissue_list', method: 'get'}).then(res => {
        this.data = res.data.list
      })
    },
    //导入
    uploader(file) {
      let formData = new FormData()
      formData.append('file', file.file)
      axios({url: '/upload', method: 'post', data: formData}).then(res => {
        console.log(res)
      })
    },
    //刷新
    shuaxin() {
      this.text = ''
    },
    // 添加组织
    add_tissue() {
      axios({url: '/tissue_list', method: 'post', data: this.form}).then(res => {
        console.log(res)
        if (res.data.code === 200) {
          alert(res.meg)
        }

      })
    }
  },
  mounted() {
    this.tissue_list()
  }
}
</script>

<style scoped>

</style>